package com.example.nacosproviderpayment9098.controller;


import com.example.common.Bean.Result;
import com.example.nacosproviderpayment9098.service.StudentService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.example.common.entity.*;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhaoren
 * @since 2020-08-31
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Resource
    private StudentService studentService;

    @GetMapping("all")
    public Result<Object> findAll(){
        List<Student> students = studentService.list();
        if (students.size() < 2){
            throw new RuntimeException("学生数量小于2！");
        }
        return Result.builder().build()
                .setData(students)
                .setStatus(HttpStatus.OK.value());
    }


}

